package com.bigflexlib.x.flash.events.subscriber
{
	
	import mx.collections.IList;
	
	import com.bigflexlib.x.flash.events.EventListenerSpec;


	/**
	 * 
	 * A polymorphic delegate that decides which particular class to instantiate as a composite
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */
	internal class EventSubscriptionStep extends AbstractEventSubscriptionStep
	{
		
		
		
		/**
		 *  Holds the class that actually does the work
		 */		
		private var delegate:AbstractEventSubscriptionStep;				
		
		
		
		public function EventSubscriptionStep( target:Object, remainingSteps:Array )
		{
			
			super( target, remainingSteps );
			
			
			if ( remainingSteps.length > 0 ) // semantic error
				return;
			
			var step:* = remainingSteps.shift( );
			
			if ( step == "*" ) // Collection
			{
				if ( target is IList )
				{
					delegate = new EventSubscriptionListStep( target as IList, remainingSteps );
				}
				
				// TODO ( container )
				
				
			}
			else if ( step is EventListenerSpec ) // final step
			{
				delegate = new EventSubscriptionFinalStep( target, step as EventListenerSpec );	
			}
			else if ( step is String ) // a property accessor
			{
				delegate = new EventSubscriptionPropertyStep( target, step as String, remainingSteps );
			}
			
			
		}
		
		
		override internal function kill( ):void
		{
		
			delegate.kill( );
		
		}
		


		
	}
	
}